<?php
/**
 * Author: Administrator
 * Date: 2022/7/16 1:22
 */

namespace DesignPatterns\Creation\Multiton;


class Multiton
{
    protected static array $instances = [];

    /**
     * 私有构造方法，无法从外部构造对象实例
     * Multiton constructor.
     */
    private function __construct()
    {
    }

    public static function getInstance($instance_name) {
        if (!isset(self::$instances[$instance_name])) {
            self::$instances[$instance_name] = new static();
        }
        return self::$instances[$instance_name];
    }

    /**
     * 防止外部克隆
     * @return void
     */
    private function __clone(){}

    /**
     * 防止外部反序列化
     * @return void
     */
    private function __wakeup(){}

}